import { eventHandler, readBody } from 'h3';
import { verifyAccessToken } from '~/utils/jwt-utils';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return { code: 401, message: '未授权访问' };
  }

  const body = await readBody(event);
  const { requestId, approvalNotes } = body;

  // 验证驳回原因
  if (!approvalNotes || approvalNotes.trim() === '') {
    return {
      code: 400,
      data: {
        success: false,
        message: '请输入驳回原因',
      },
      message: '请输入驳回原因',
    };
  }

  // 模拟驳回操作
  // 这里应该更新数据库，这里用模拟数据

  return {
    code: 200,
    data: {
      success: true,
      message: '驳回成功',
    },
    message: '驳回成功',
  };
});
